package com.yanqu.road.dao.impl.activity.tanghulu;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.tanghulu.TangHuLuScoreInfo;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class TangHuLuConfigDaoImpl extends TempDao {


    public static String getTangHuLuScoreInfoSql = "select * from t_s_activity_score where activityId = ?";
    public List<TangHuLuScoreInfo> getTangHuLuScoreInfo(int activityId){
        ResultSet rs = null;
        CallableStatement call = null;
        List<TangHuLuScoreInfo> result = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getTangHuLuScoreInfoSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                TangHuLuScoreInfo tangHuLuScoreInfo = new TangHuLuScoreInfo();
                tangHuLuScoreInfo.setId(rs.getInt("id"));
                tangHuLuScoreInfo.setName(rs.getString("name"));
                tangHuLuScoreInfo.setDesc(rs.getString("desc"));
                tangHuLuScoreInfo.setNumRange(StringUtils.stringToIntegerList(rs.getString("num"), ","));
                tangHuLuScoreInfo.setIntegral(rs.getInt("integral"));
                result.add(tangHuLuScoreInfo);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }
}
